﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kooboo.Commerce.AddIn;
using Kooboo.IoC;

namespace Kooboo.Commerce
{
    public static class PromotionRuleCommand
    {
        public static IPromotion FindPromotion(this IPromotionRule rule)
        {
            return ObjectContainer.CreateInstances<IPromotion>()
                .Where(i => i.Name == rule.PromotionName)
                .FirstOrDefault();
        }

        public static void RemoveSeftReference(this IPromotionRule rule)
        {
            var self = rule.KillRules.Where(i => i.Id == rule.Id).FirstOrDefault();

            if (self != null)
            {
                rule.KillRules.Remove(self);
            }

        }
    }
}
